package graphics;

import ship.*;
import util.*;
import util.Point;

import java.awt.*;
import java.awt.image.*;

import main.Game;


public class ShipControlPanelOld {
	private Ship ship;
	private Point loc;
	private Point dim;

	private BufferedImage buffer;
	
	private Color[] states = { Color.green, Color.yellow, Color.red};
	
	private DropDownMenu test = new DropDownMenu(new Point(0, 100), "Weapon 1");
	
	
	public ShipControlPanelOld(Point loc, Point dim) {
		this.ship = Game.game.getShip();
		this.loc = loc;
		this.dim = dim;

		buffer = new BufferedImage((int) dim.getX(), (int) dim.getY(), BufferedImage.TYPE_INT_BGR);
	}
	
	
	
	public void draw(MaxGraphics g) {
		MaxGraphics mg = new MaxGraphics((Graphics2D) buffer.getGraphics());
		mg.setColor(Color.lightGray);
		mg.fillRectUL(0, 0, dim.getX(), dim.getY());
		mg.translate(50, 50);
		
		
		Polygon[] cons = ShipConstants.model;
		mg.setColor(Color.black);
		mg.drawText(50, 0, "Shields: " + ship.getShields() * 100 + "%");
		for(int i = 0; i < cons.length; i++) {
			mg.setColor(states[ship.getDamage(i)]);
			mg.fillPolygon(cons[i]);
		}
		mg.setColor(Color.black);
		for(int i = 0; i < cons.length; i++) {
			mg.drawPolygon(cons[i]);
		}
		
		drawEng(mg);
		
		int offset = 80 + 30 * ShipConstants.systems.length+1;
		
		if(ship.getTimeTillJump() == 0) {
			mg.drawText(-40, offset, "Jump: Ready");
			offset += 20;
		}
		if(ship.getTimeTillJump() > 0) {
			mg.drawText(-40, offset, "Jump: " + ship.getTimeTillJump());
			offset += 20;
		}
		
		mg.translate(-50, -50);
		g.drawImage(buffer, loc.getX(), loc.getY());
		
	}
	

	public void handleClick(Point p) {
		p = p.translate(-loc.getX(), -loc.getY());
		p = p.translate(-50, -50);
		//pips.handleClick(p);
	}
	
	public void drawEng(MaxGraphics g) {
		for(int i = 0; i < ShipConstants.systems.length; i++) {			
			g.drawText(-40, 60 + 30* i, ShipConstants.systems[i]);
		}

		g.drawText(-40, 60 + 30 * ShipConstants.systems.length+1, "Spare: " + ship.sparePower());
		Point cords = new Point(35, 55);
		g.translate(cords.getX(), cords.getY());
		int[] pips = ship.getPower();
		for(int i = 0; i < pips.length; i++) {
			for(int j = 0; j < 4; j++) {
				g.setColor(Color.black);
				g.drawRect(j * 30, i * 30, 20, 20);
				if(j < pips[i]) {
					g.setColor(Color.GREEN);
					g.fillRect(j * 30, i * 30, 18, 18);
				}
			}
		}
		
		test.draw(g);
		
		g.translate(-cords.getX(), -cords.getY());
	}
	
}
